package com.ibm.risk.irmp.base.auth.entity;

import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.BatchSize;

import java.util.List;

@Data
//@Accessors(chain = true)
@Entity
@Table(name = "ri_base_auth_user")
@NamedQueries({
        @NamedQuery(name = "SystemUser.findByUsername", query = "SELECT u FROM SystemUser u WHERE u.username = :username"),
        @NamedQuery(name = "SystemUser.findByUserSn", query = "SELECT u FROM SystemUser u WHERE u.userSn = :userSn")
})
public class SystemUser extends SystemUserBase {
    private String password;

    @OneToMany
    @BatchSize(size = 50)
    @JoinTable(name ="ri_base_auth_role_user",
            joinColumns = @JoinColumn(name = "username"), inverseJoinColumns = @JoinColumn(name = "role_code"))
    private List<SystemRole> roles;

    @OneToMany
    @BatchSize(size = 50)
    @JoinTable(name ="ri_base_auth_mng_branch_user",
            joinColumns = @JoinColumn(name = "username"), inverseJoinColumns = @JoinColumn(name = "branch_code"))
    private List<SystemMngBranch> mngOrgs;

    @OneToMany
    @BatchSize(size = 50)
    @JoinTable(name ="ri_base_auth_biz_branch_user",
            joinColumns = @JoinColumn(name = "username"), inverseJoinColumns = @JoinColumn(name = "branch_code"))
    private List<SystemBizBranch> bizOrgs;
}
